import cv2
import numpy as np


def GrayScaleLiner(
    img:np.ndarray, 
    b_factor:float = 1.0, 
    b_offset:int = 10, 
    g_factor:float=1.0, 
    g_offset:int=-10, 
    r_factor:float=1.0, 
    r_offset:int=-30) -> np.ndarray:
    '''
    线性调整每个通道的灰度
    :param img:np.ndarray 输入图像数据
    :param b_factor:float blue factor
    :param b_offset:int blue offset
    :param g_factor:float green factor
    :param g_offset:int green offset
    :param r_factor:red factor
    :param r_offset:red offset
    :return:np.ndarray 处理后的图片
    '''
    b_ = 0
    g_ = 1
    r_ = 2
    img_out_ = np.zeros(img.shape, np.uint8)    # 输出的图像
    img_out_[:,:,b_] = np.clip(b_factor * img[:,:,b_] + b_offset, 0, 255)
    img_out_[:,:,g_] = np.clip(g_factor * img[:,:,g_] + g_offset, 0, 255)
    img_out_[:,:,r_] = np.clip(r_factor * img[:,:,r_] + r_offset, 0, 255)
    return img_out_

def Brightness(img: np.ndarray, factor:float, offset:int) -> np.ndarray:
    '''
    线性的调整亮度
    :param img:np.ndarray 输入图像
    :param factor:float factor
    :param offset:int offset
    :return:np.ndarray 处理后的图片
    '''
    img_out_ = np.zeros(img.shape, np.uint8)    # 输出的图像
    img_out_[:,:,:] = np.clip(factor * img[:,:,:] + offset, 0, 255)
    return img_out_

def Gama_transfer(img,power1):
    img = 255*np.power(img/255,power1)
    img = np.around(img)
    img[img>255] = 255
    img_out_ = img.astype(np.uint8)
    return img_out_

